import demo.MyLinkedList;
import stackdemo.MyStack;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Stack;

public class Test {
    /**
     * 栈的引用场景
     * @param args
     *      1.改变元素序列
     *      2.逆序打印
     *      3.栈相关题
     */
    public static void main(String[] args) {

    }
    public static void main4(String[] args) {
        /**
         * 顺序表实现Stack:头插 头删
         * 链表实现Stack:头插 头删 尾插 尾删均可
         * 要求:删除 添加 时间复杂度为O(n)
         * @param args
         */
    }
    /**
     * 栈的实现
     */
    public static void main3(String[] args) {
        MyStack stack = new MyStack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);

        System.out.println(stack.pop());
        System.out.println(stack.peek());
        System.out.println(stack.isEmpty());
    }
    /**
     * LinkedList的遍历
     * @param args
     */
    public static void main2(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        //直接打印
        System.out.println(list);
        //for循环
        for(int i = 0;i < list.size();i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
        //for-each循环
        for(int i : list) {
            System.out.print(i+ " ");
        }
        System.out.println();
        //迭代器:顺序打印
        ListIterator<Integer> it = list.listIterator();
        while(it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();
        //迭代器:逆序打印
        ListIterator<Integer> it2 = list.listIterator(list.size());
        while(it.hasPrevious()) {
            System.out.print(it.previous() + " ");
        }
        System.out.println();
    }
    public static void main1(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        //头插
//        myLinkedList.addFirst(1);
//        myLinkedList.addFirst(2);
//        myLinkedList.addFirst(3);
//        myLinkedList.addFirst(4);
//        myLinkedList.addFirst(5);
//        myLinkedList.display();
        //尾插
        myLinkedList.addLast(1);
        myLinkedList.addLast(1);
        myLinkedList.addLast(1);
        myLinkedList.addLast(1);
        myLinkedList.addLast(1);
        myLinkedList.display();
        //任意位置插入
//        myLinkedList.addIndex(2,11);
//        myLinkedList.display();
        //删除元素key
        myLinkedList.remove(1);
        myLinkedList.display();
        //删除所有元素key
        myLinkedList.removeAllKey(1);
        myLinkedList.display();
        //清除
        myLinkedList.clear();
        myLinkedList.display();
    }
}
